import * as path from 'path';
import nested from 'postcss-nested';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import htmlTemplate from 'rollup-plugin-fill-html';
import livereload from 'rollup-plugin-livereload';
import nodeResolve from 'rollup-plugin-node-resolve';
import postcss from 'rollup-plugin-postcss';
import serve from 'rollup-plugin-serve';
import tslint from 'rollup-plugin-tslint';
import typescript from 'rollup-plugin-typescript2';

const DEV_DIR = '.runtime';

export default [
  {
    input: 'src/index.ts',
    output: {
      name: 'DocWriter',
      file: path.join(DEV_DIR, 'doc-writer.js'), // DIST_DIR + 'doc-writer.js',
      sourcemap: 'inline',
      format: 'umd',
    },
    plugins: [
      htmlTemplate({
        template: 'src/template.html',
        filename: 'index.html',
      }),
      tslint(),
      typescript(),
      serve({
        contentBase: [DEV_DIR, 'public'],
        host: '0.0.0.0',
      }),
      livereload({
        watch: DEV_DIR,
      }),
      postcss({
        extract: DEV_DIR + '/styles/doc-writer.min.css',
        inject: false,
        minimize: {
          safe: true,
        },
        plugins: [nested()],
        extensions: ['.pcss', '.css'],
      }),
      nodeResolve({
        jsnext: true,
        main: true,
      }),
      babel({
        exclude: 'node_modules/**',
      }),
      commonjs(),
      // replace({}),
    ],
  },
];
